package b3.widget.match
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.util.*;
	import b3.widget.basic.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	
	public class MatchWinBox extends BasicWidget
	{
		private const WIN_BRIEF:Array = ["实际排名将以<font color='#FF0000' size='18'> 今日比赛结束时 </font>为准，奖品将以邮件方式发到您的包裹。", 
			"实际排名将以<font color='#FF0000' size='18'> 本周比赛结束时 </font>为准，奖品将以邮件方式发到您的包裹。", 
			"实际排名将以<font color='#FF0000' size='18'> 本月比赛结束时 </font>为准，奖品将以邮件方式发到您的包裹。", 
			"总排行的奖品将由管理员<font color='#FF0000' size='18'> 不定时 </font>发送。敬请关注论坛动态！"];
			  
		public function MatchWinBox(match:Match, rankType:int, ranking:int)
		{
			super();
			var matchConfig:MatchConfig = Config.matchConfigs[match.index];
			//背景
			var TaskAccomplishBgr:Class = ResourceHelper.getInstance().getClassByName("TaskAccomplishBgr");
			addChild(new TaskAccomplishBgr());
			//标题
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.CENTER;
			titleText.defaultTextFormat = new TextFormat("微软雅黑", 18, 0x000000, true);
			titleText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			titleText.htmlText = "恭喜您！获得了" + MatchConfig.RANK_NAME[rankType] + 
				"第<font color='#FF0000' size='18'> " + (ranking + 1).toString() + " </font>名！";
			titleText.x = (this.width - titleText.width) / 2;
			titleText.y = 32;
			addChild(titleText);
			
			//奖杯
			var CupImg:Class = ResourceHelper.getInstance().getClassByName("GoldCup");
			var cupImg:Sprite = new CupImg();
			cupImg.x = 110;
			cupImg.y = 120;
			addChild(cupImg);

			//排行
			var rankingText:TextField = new TextField();
			rankingText.selectable = false;
        	rankingText.autoSize = TextFieldAutoSize.CENTER;
			rankingText.defaultTextFormat = new TextFormat("微软雅黑", 20, 0xAAAA00, true);
			rankingText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			rankingText.x = 160;
			rankingText.y = 200;
			rankingText.text = MatchConfig.RANK_NAME[rankType] + ": " + (ranking + 1).toString() + 
				(ranking < 3 ? MatchConfig.RANK_TAIL[ranking] : MatchConfig.RANK_TAIL[3]);
			addChild(rankingText);
			
			//比赛结果描述
			var resultBriefField:TextField = new TextField();
			resultBriefField.selectable = false;
        	resultBriefField.autoSize = TextFieldAutoSize.LEFT;
        	resultBriefField.width = 190;
        	resultBriefField.wordWrap = true;
        	resultBriefField.multiline = true;
			resultBriefField.defaultTextFormat = new TextFormat(BFont.fontName, 15, 0x000000);
			resultBriefField.x = 235;
			resultBriefField.y = 125; 
			resultBriefField.htmlText = WIN_BRIEF[rankType] + "<br><font color='#0000FF'>请您随时留意排名的变化~</font>";
			addChild(resultBriefField);
			
			//确定按钮
			var ButtonBgr:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr0");
			var buttonOK:BasicButton = new BasicButton(ButtonBgr, "确定");
			buttonOK.x = (this.width  - buttonOK.width) / 2;
			buttonOK.y = 245;
			buttonOK.addEventListener(MouseEvent.CLICK, onButtonOKClick);
			addChild(buttonOK);

			//彩带
			var ColorPaper:Class = ResourceHelper.getInstance().getClassByName("ColorPaper");
			var colorPaper:Sprite = new ColorPaper();
			colorPaper.x = 40;
			colorPaper.y = 30;
			addChild(colorPaper);
			colorPaper = new ColorPaper();
			colorPaper.scaleX = -1;
			colorPaper.x = this.width - 40;
			colorPaper.y = 30;
			addChild(colorPaper);
			this.anchor = ANCHOR_MIDDLE_MIDDLE;
			this.effect = EFFECT_EXPAND;
			this.x = - this.width / 2;
			this.y = - this.height / 2; 
			this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		
		private function onAddedToStage(event:Event):void
		{
			BSound.getInstance().playEffect("SoundAchievementReached");
		}
		
		private function onButtonOKClick(event:MouseEvent):void
		{
			close();
		}
        
	}
}